package com.bestcem.xm.deliver.mq.receiver.biz.rabbit;

import com.alibaba.fastjson.JSONObject;
import com.bestcem.xm.deliver.mq.dto.*;
import com.bestcem.xm.deliver.mq.receiver.biz.DeliverConsumers;
import com.bestcem.xm.deliver.mq.receiver.biz.ReceiverService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;

import java.util.function.Consumer;

@Slf4j
@Component
@ConditionalOnProperty(prefix = "application", name = "mqType", havingValue = "rabbit")
public class RabbitConsumers implements DeliverConsumers {

    private final ReceiverService receiverService;

    public RabbitConsumers(ReceiverService receiverService) {
        this.receiverService = receiverService;
    }

    //private ReceiverService receiverService;
    //
    //@Autowired
    //public void setReceiverService(ReceiverService receiverService) {
    //    this.receiverService = receiverService;
    //}

    @Bean
    @Override
    public Consumer<GenericMessage<WechatmpDeliverMessageDto>> wechatmpDeliver() {
        return receiverService::wechatmpDeliver;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<EmailDeliverMessageDto>> emailDeliver() {
        return receiverService::emailDeliver;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<SmsDeliverMessageDto>> smsDeliver() {
        return receiverService::smsDeliver;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<CustomDeliverLinkMessageDto>> saveCustomDeliverLink() {
        return receiverService::saveCustomDeliverLink;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<CreateProjectDto>> qdesProjectCreated() {
        return receiverService::qdesProjectCreated;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<DeleteProjectDto>> projectDeleted() {
        return receiverService::projectDeleted;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<JSONObject>> projectQuestionDelete() {
        return receiverService::projectQuestionDelete;
    }

    //@mq.subscribe(topics.survey_respondent_unfinish)
    //@mq.subscribe(topics.survey_respondent_submit)
    //async def deliver_survey_respondent_submit(data):
    @Bean
    @Override
    public Consumer<GenericMessage<JSONObject>> deliverSurveyRespondentSubmit() {
        return receiverService::deliverSurveyRespondentSubmit;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<JSONObject>> deliverSurveyRespondentUnfinish() {
        return receiverService::deliverSurveyRespondentSubmit;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<JSONObject>> defaultDeliverStoreInvalidate() {
        return receiverService::defaultDeliverStoreInvalidate;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<JSONObject>> userGroupTitleModifyList() {
        return receiverService::userGroupTitleModifyList;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<JSONObject>> userNewStoreList() {
        return receiverService::userNewStoreList;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<JSONObject>> userGroupInvalidate() {
        return receiverService::userGroupInvalidate;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<OpenplatformExtParamUpdateDto>> extparamUpdate() {
        return receiverService::extparamUpdate;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<OpenplatformExtParamUpdateDto>> deliverSurveyExtVersionUpdate() {
        return receiverService::deliverSurveyExtVersionUpdate;
    }

    @Bean
    @Override
    public Consumer<GenericMessage<JSONObject>> surveyRespondentSync() {
        return receiverService::surveyRespondentSync;
    }
}
